package com.xingongchang.baolebei.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.insthub.BeeFramework.adapter.BeeBaseAdapter;
import com.xingongchang.baolebei.R;
import com.xingongchang.baolebei.protocol.CATEGORY;

public class CategoryAdapter extends BeeBaseAdapter {

	public class CategoryHolder extends BeeCellHolder {
		TextView categoryName;
		ImageView rightArrow;
	}

	public CategoryAdapter(Context c, ArrayList dataList) {
		super(c, dataList);
	}

	@Override
	protected BeeCellHolder createCellHolder(View cellView) {
		CategoryHolder holder = new CategoryHolder();
		holder.categoryName = (TextView) cellView
				.findViewById(R.id.category_name);
		holder.rightArrow = (ImageView) cellView.findViewById(R.id.right_arrow);
		return holder;
	}

	@Override
	protected View bindData(int position, View cellView, ViewGroup parent,
			BeeCellHolder h) {
		CATEGORY categoryItem = (CATEGORY) dataList.get(position);
		CategoryHolder holder = (CategoryHolder) h;
		holder.categoryName.setText(categoryItem.name);
		if (categoryItem.children.size() > 0) {
			holder.rightArrow.setVisibility(View.VISIBLE);
		} else {
			holder.rightArrow.setVisibility(View.GONE);
		}
		return cellView;
	}

	@Override
	public View createCellView() {
		View cellView = mInflater.inflate(R.layout.category_cell, null);
		return cellView;
	}
}
